home *** CD-ROM | disk | FTP | other *** search
- Path: gail.ripco.com!mambuhl
- From: mambuhl@ripco.com (Martin Ambuhl)
- Newsgroups: comp.lang.c
- Subject: Re:Halp! I don`t know wha
- Date: 5 Feb 1996 21:37:35 GMT
- Organization: Ripco Communications, Inc.
- Message-ID: <4f5tav$etm@gail.ripco.com>
- NNTP-Posting-Host: foley.ripco.com
-
- etoivane@direct.ca (Ed Toivanen)
- in <4eu8sl$f27@aphex.direct.ca> asks:
-
- >I've been at this for a couple *days* and can't get it to work.
- >It's supposed to graph a function entered at the command line,
- >eg. "c:\>graph 2 1" should graph out 2x+1 to stdout using the '*'
- >character. Can anybody help me please?
-
- If you get a bunch of stars at strange places (likely with MSDOS),
- you were unlucky. The correct version of "not working" is a segfault,
- since you are trashing argv.
-
- #if 0
- /* mha - this is the original code */
- for (x = minDomain; x < maxDomain; x++) {
- degree = argc - 1;
- while (degree--) {
- y = ((atol(*++argv)) * (power(x, degree))) + y;
- if (y > maxRange || y < minRange)
- y = 0;
- }
- lin[y + RCORR][x + DCORR] = '*';
- }
- #endif
- /* mha - this is a possible replacement */
- {
- int ncoeff = argc - 1, i;
- double *coeff;
- if (!(coeff = malloc(ncoeff * sizeof(double)))) {
- fprintf(stderr, "Cannot allocate space for coeff\n");
- exit(EXIT_FAILURE);
- }
- for (i = 0; i < ncoeff; i++)
- sscanf(argv[i + 1], "%le", &coeff[i]);
- for (x = minDomain; x < maxDomain; x++) {
- for (y = 0, i = 0; i < ncoeff; i++)
- y = y * x + coeff[i];
- if (y + RCORR >= 0 && y + RCORR <= RANGE)
- lin[y + RCORR][x + DCORR] = '*';
- }
- free(coeff);
- }
-
-
- --
- * Martin Ambuhl net: mambuhl@ripco.com
- * Chicago, IL (USA)
-